package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 插入数据
     *
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    /**
     * 历史订单分页查询
     *
     * @return
     */
    Page<Orders> select(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单Id查询信息
     *
     * @param id
     * @return
     */
    @Select("select id, number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status" +
            " from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 根据状态查询订单数量
     *
     * @return
     */
    @Select("select count(*) from orders where status = #{status}")
    Integer getCountByStatus(Integer status);

    /**
     * 查询超时订单
     *
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrdertime(Integer status, LocalDateTime orderTime);

    /**
     * 计算每天的营业额
     *
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     * 获取订单数量
     *
     * @param map
     * @return
     */
    Integer getByMap(Map map);

    /**
     * 查询Top10销量数据
     *
     * @param map
     * @return
     */
    List<GoodsSalesDTO> getSalesTop10ByMap(Map map);
}
